package day02;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 输入一个数学计算表达式，如:1+2
 * 然后输出计算后的结果:1+2=3
 * 这里计算表达式只计算一次即可，可以使用加减乘除任意一个,可以进行小数运算。
 * @author Bonnie
 *
 */
public class Test07 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入");
        String s= sc.next();
        String[] split = s.split("\\+|\\-|\\*|\\/");
        boolean matches = s.matches("(\\d+\\.\\d|\\d+)+\\+{1}(\\d+\\.\\d|\\d+)");
        boolean matches1 = s.matches("(\\d+\\.\\d|\\d+)+\\-{1}(\\d+\\.\\d|\\d+)");
        boolean matches2 = s.matches("(\\d+\\.\\d|\\d+)+\\*{1}(\\d+\\.\\d|\\d+)");
        boolean matches3 = s.matches("(\\d+\\.\\d|\\d+)+\\/{1}(\\d+\\.\\d|\\d+)");
        Double aDouble = Double.valueOf(split[0]);
        Double bDouble = Double.valueOf(split[1]);
        if(matches){
            System.out.println(aDouble+"+"+bDouble+"="+(aDouble+bDouble));
        }
        else if(matches1){
            System.out.println(aDouble+"-"+bDouble+"="+(aDouble-bDouble));
        }
        else if(matches2){
            System.out.println(aDouble+"*"+bDouble+"="+(aDouble*bDouble));
        }
        else if(matches3){
            System.out.println(aDouble+"/"+bDouble+"="+(aDouble/bDouble));
        }
    }
}
